﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Web;
using PowerCreator.LMS.Common.Upload;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Grade.Entity;

public partial class sysadmin_CourseManager_CourseResourceType : PowerCreator.LMS.Web.Base.BasePage
{
    Course opCourse = new Course();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BinderResourceTypeRPT();
        }
    }
    private void BinderResourceTypeRPT()
    {
        string search = "";
        DataTable dt = opCourse.QueryResourceType(search);
        ArrayList list = opCourse.GetResourceTypeTree(dt);
        rpt_RestpName.DataSource = list;
        rpt_RestpName.DataBind();

        for (int i = 0; i < rpt_RestpName.Items.Count; i++)
        {
            Button btnadd = (Button)rpt_RestpName.Items[i].FindControl("btn_Add");
            btnadd.Text = GetLanageValueByKey("btn_AddNew", PowerCreator.LMS.Language.LanagetItemType.Page);
            Button btn_Editor = (Button)rpt_RestpName.Items[i].FindControl("btn_Editor");
            btn_Editor.Text = GetLanageValueByKey("ManagerRole_gv_lnk_o1", PowerCreator.LMS.Language.LanagetItemType.Page);
            Button Button1 = (Button)rpt_RestpName.Items[i].FindControl("Button1");
            Button1.Text = GetLanageValueByKey("ManagerRole_gv_lnk_o2", PowerCreator.LMS.Language.LanagetItemType.Page);
            int tid = 6;
            Label lblCatalogID = (Label)rpt_RestpName.Items[i].FindControl("lblCatalogID");
            tid = int.Parse(lblCatalogID.Text);
            if (tid < 6)
            {
                btnadd.Enabled = false;
                //btn_Editor.Enabled = false;
                Button1.Enabled = false;
            }
     }

        //ddl_ResourceType.DataSource = list;
        //ddl_ResourceType.DataTextField = "Text";
        //ddl_ResourceType.DataValueField = "Value";
        //ddl_ResourceType.DataBind();
        //ListItem li = new ListItem();
        //li.Text = GetLanageValueByKey("AddTrainProjectType_db_d1", PowerCreator.LMS.Language.LanagetItemType.Page);
        //li.Value = "0";
        //ddl_ResourceType.Items.Insert(0, li);
    }

    protected void rpt_RestpName_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string ul="";
        ViewState["ResourceType:OpTypeID"] = e.CommandArgument.ToString();
        if (e.CommandName == "btnadd")
        {
            ul = "AddCourseResourceType.aspx";
            //ViewState["ResourceType:OpType"] = "add";
            //ddl_ResourceType.SelectedValue = ViewState["ResourceType:OpTypeID"].ToString();
            //txt_CourseResourceType.Value = "";
            Script.RedirectURL(ul);
        }
        else if (e.CommandName == "btnedit")
        {
            ul = "AddCourseResourceType.aspx?tid=" + ViewState["ResourceType:OpTypeID"].ToString();
            Script.RedirectURL(ul);

            //ViewState["ResourceType:OpType"] = "edit";
            //VOTResourceType vo = opCourse.LoadResourceType(int.Parse(ViewState["ResourceType:OpTypeID"].ToString()));
            //ddl_ResourceType.SelectedValue = vo.RestpFatherID.ToString();
            //txt_CourseResourceType.Value = vo.RestpName;
        }
        else if (e.CommandName == "btndel")
        {
            ViewState["ResourceType:OpType"] = "del";
            if (opCourse.DeleResourceType(int.Parse(ViewState["ResourceType:OpTypeID"].ToString())))
            {
                BinderResourceTypeRPT();
            }
            else
            {
                Label lblmsg = (Label)e.Item.FindControl("lbl_msg_description");
                lblmsg.Text = "删除失败!";                
            }
            //int count = opCourse.QueryResourceTypeParent(int.Parse(ViewState["ResourceType:OpTypeID"].ToString()));
            //if (count > 1)
            //{
            //    Label lblmsg = (Label)e.Item.FindControl("lbl_msg_description");
            //    //lblmsg.Text = "资源分类下有子分类，不允许删除该分类信息!";
            //    lblmsg.Text = GetLanageValueByKey("AddResourceInfo_gv_m1", PowerCreator.LMS.Language.LanagetItemType.Page);
            //}
            
        }
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "showmy1", "<script>showFloat()</script>");
    }

    //protected void btn_addresourcetype_Click(object sender, EventArgs e)
    //{
    //    if (!CheckResourceTypePageData())
    //    {
    //        Page.ClientScript.RegisterStartupScript(Page.GetType(), "showmy1", "<script>showFloat()</script>");
    //        return;
    //    }

    //    VOTResourceType vo = new VOTResourceType();
    //    //vo.RestpName = txt_CourseResourceType.Value;
    //    //vo.RestpFatherID = int.Parse(ddl_ResourceType.SelectedValue.ToString());
    //    vo.RestpIsTop = 0;
    //    vo.RestpOrderBy = 0;
    //    vo.RestpLayer = opCourse.QueryResourceTypeLayer(vo.RestpFatherID);


    //    if (ViewState["ResourceType:OpType"].ToString() == "add")
    //    {
    //        if (opCourse.AddResourceType(vo))
    //        {
    //            //BinderCourseResourceType();
    //            BinderResourceTypeRPT();
    //        }
    //    }
    //    else if (ViewState["ResourceType:OpType"].ToString() == "edit")
    //    {
    //        vo.RestpID = int.Parse(ViewState["ResourceType:OpTypeID"].ToString());
    //        if (opCourse.UpdateResourceType(vo))
    //        {
    //            //BinderCourseResourceType();
    //            BinderResourceTypeRPT();
    //        }
    //    }
    //}

    //private bool CheckResourceTypePageData()
    //{
    //    if (string.IsNullOrEmpty(txt_CourseResourceType.Value))
    //    {
    //        lbl_addcourseresourcetype_msg_courseresourcetypename.Text = GetLanageValueByKey("AddResourceInfo_msg_m8", PowerCreator.LMS.Language.LanagetItemType.Page);
    //        return false;
    //    }
    //    string search = string.Format("RestpName='{0}'", txt_CourseResourceType.Value);

    //    if (ViewState["ResourceType:OpType"].ToString() == "edit")
    //    {
    //        search += " and RestpID <> " + ViewState["ResourceType:OpTypeID"].ToString();
    //    }

    //    if (opCourse.QueryResourceTypeCount(search) != 0)
    //    {
    //        lbl_addcourseresourcetype_msg_courseresourcetypename.Text = GetLanageValueByKey("AddResourceInfo_msg_m9", PowerCreator.LMS.Language.LanagetItemType.Page);
    //        return false;
    //    }
    //    return true;
    //}
}
